home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
tifreadr.sit
/
Tiff Window DEMO
/
Open Color Window.c
< prev
next >
Wrap
Text File
|
1990-04-21
|
5KB
|
122 lines
#include "my color.h"
PixMapHandle read_tiff_file(CWindowPtr);
void dispose_of_TIFF(CWindowPtr); /* Dispose of all the CGrafPtr variables!! */
OpenWindow() /* Open a new window */
{
Rect resize_rect;
CGrafPtr the_tiff_picture; /* to receive the off screen PixMap containing the TIFF picture */
char wNameDef[256]; /* to hold our default window title */
char nextWTitle[256]; /* title of next window to be opened*/
char *wName;
ControlHandle control; /* I'll adjust all the scroll bars to accommodate the size of the TIFF picture */
PaletteHandle WindowPalette;
NumToString (nextWNum, nextWTitle); /* prepare number for title -- returns C string */
PtoCstr(nextWTitle); /* convert to 'C' type string */
strcpy((char *)wNameDef,WindName); /* WindName is a #define */
wName = (char *)strcat((char *)wNameDef,(char *)nextWTitle);
CtoPstr(wNameDef); /* convert to 'PASCAL' type string */
myWindow = (CWindowPtr)NewCWindow (nil, &nextWRect, wNameDef, true, documentProc,
(CWindowPtr)-1, true, 0);
WindowPalette = GetNewPalette(0);
SetPalette(myWindow, WindowPalette, TRUE);
SetPort (myWindow); /*make it the current port*/
add_scroll_bars(myWindow); /* create some scroll bars for the new window */
set_color(myWindow); /* set the window's color to something hideous */
OffsetRect (&nextWRect, windDX, windDY);/*move window down and right*/
if (nextWRect.right > dragRect.right) /*move back if it's too far over*/
OffsetRect (&nextWRect, -nextWRect.left + leftEdge, 0);
if (nextWRect.bottom > dragRect.bottom)
OffsetRect (&nextWRect, 0, -nextWRect.top + topEdge);
nextWNum++; /*bump number for next window*/
the_tiff_picture = (CGrafPtr)read_tiff_file(myWindow); /* Now read the TIFF file for this window */
if(the_tiff_picture) /* If we successfully read a TIFF file, then resize the window to accommodate the image */
{
resize_rect = (**(*the_tiff_picture).portPixMap).bounds;
if((resize_rect.right + BAR_WIDTH) > screenBits.bounds.right)
resize_rect.right = screenBits.bounds.right - (4 * BAR_WIDTH);
if((resize_rect.bottom + BAR_WIDTH) > screenBits.bounds.bottom)
resize_rect.bottom = screenBits.bounds.bottom - (4 * BAR_WIDTH);
SizeWindow(myWindow, resize_rect.right + BAR_WIDTH,
resize_rect.bottom + BAR_WIDTH, TRUE); /* resize the window to hold the TIFF picture */
adjust_scroll_bars(myWindow);
control = ((CWindowPeek)myWindow)->controlList;
while(control) /* set the control's maximum value to be the size of the TIFF rect */
{
if(GetCRefCon(control) == (long)VERTICLE_SCROLL)
SetCtlMax(control, (**(*the_tiff_picture).portPixMap).bounds.bottom);
else if(GetCRefCon(control) == (long)HORIZONTAL_SCROLL)
SetCtlMax(control, (**(*the_tiff_picture).portPixMap).bounds.right);
control = (*control)->nextControl;
}
(*the_tiff_picture).portRect = resize_rect;
SetWRefCon(myWindow, the_tiff_picture); /* make the window point to the off screen Pix map containing the TIFF picture */
}
else
SetWRefCon(myWindow, 0L); /*We could not open the TIFF picture, make the window as containing no TIFF pictures */
menusOK = false;
EnableItem (myMenus [editM],0); /*in case this is the only window*/
} /* OpenWindow */
KillWindow(theWindow) /*Close a window and throw everything away*/
CWindowPtr theWindow;
{
CWindowPtr front_window;
extern Boolean file_in_use;
front_window = (CWindowPtr)FrontWindow();
dispose_of_TIFF(front_window);
DisposeWindow (theWindow);
/* throw away WindowRecord */
front_window = (CWindowPtr)FrontWindow();
if (front_window == nil) /*if no more windows, disable Close*/
{
DisableItem (myMenus[fileM], closeItem);
SetCursor(&arrow);
}
else /* FrontWindow() != nil */
{
if (((CWindowPeek)front_window)->windowKind < 0)
/*if a desk acc is coming up, enable undo*/
{
EnableItem (myMenus[editM], undoItem);
SetCursor(&arrow);
}
else
DisableItem (myMenus[editM], undoItem);
} /* else */
} /*KillWindow*/
void dispose_of_TIFF(front_window) /* Dispose of all the CGrafPtr variables!! */
CWindowPtr front_window;
{
PaletteHandle picture_palette;
CGrafPtr the_picture;
the_picture = (CGrafPtr)((CWindowPeek)front_window)->refCon;
if(the_picture)
{
picture_palette = GetPalette(front_window);
DisposePalette(front_window);
DisposHandle((**(*the_picture).portPixMap).pmTable);
DisposPtr((**(*the_picture).portPixMap).baseAddr);
DisposHandle((*the_picture).portPixMap);
DisposPtr(the_picture);
}
return;
}